#!/usr/bin/php
<?php
//               _    _
//    __   _____| | _| |_ ___  _ __ _ __ __ _ _   _ _ __ ___
//    \ \ / / _ \ |/ / __/ _ \| '__| '__/ _` | | | | '_ ` _ \
//     \ V /  __/   <| || (_) | |  | | | (_| | |_| | | | | | |
//      \_/ \___|_|\_\\__\___/|_|  |_|  \__,_|\__,_|_| |_| |_|
//
//    checkpassword-oath

// Verify correct usage
if($args>3 || argc==1) {
    echo "usage: checkpassword_addextended.php username [password]\n";

    exit(1);
}

$username = $argv[1];

$password = '';

// Check for password input on standardin
if($argc==2) {
    echo "Password: ";
    system('stty -echo');
    $password = trim(fgets(STDIN));
    system('stty echo');
    // add a new line since the users CR didn't echo
    echo "\n";
} else {
    $password = $argv[2];
}

// deactivate execution of the script
$dont_authorize = true;

// Include file and supress output
ob_start();
@require('checkpassword.php');
ob_clean();

// get the user id
$user_data = $checkPass->fetchUser($username);

// add the password
$checkPass->addExtended($user_data['id'], $password);

echo "password added\n"



?>